<?php
namespace app\frontend\controller;
use think\Db;
use think\Controller;
class Test extends Controller
{
    public function index()
    {
    	$user_id='3';
    	$date2=db('order')->where("user_id={$user_id} and status=1")->select();
    	dump($date2);
   
           for($i=0;$i<count($date2);$i++)
         {
         	$alldate2=$date2[$i]; 
         	dump($alldate2);
         	$shopcart_id2=$alldate2['shopcart_id'];
         	dump($shopcart_id2);
		    $shopcartId2=explode(',', $shopcart_id2);
		    dump($shopcartId2);
		   foreach ($shopcartId2 as $key ) {
		   	if($key!='')
		   	{
		   		$shopcartId1[]=$key;
		   	}
		   }


		    
		    dump($shopcartId1);
		   
         }
         $result=db('shopcart')->where(array('shopcart_id'=>array('in',$shopcartId1)))->field('product_number')->select();
         dump($result);
         $result1=array_column($result, 'product_number');
         dump($result1);
              
     }
      public function test1()
    {
    	$user_id='3';
    	$date2=db('order')->where("user_id={$user_id} and order_id='31'")->order('order_id asc')->limit(1)->select();
    	dump($date2);
    	foreach ($date2 as $key) {
    		$shopcart_id=$key['shopcart_id'];
    	}
    	dump($shopcart_id);
    	 $result=db('shopcart')->where(array('shopcart_id'=>array('in',$shopcart_id)))->field('product_number')->select();
    	 dump($result);
    	 $result1=array_column($result, 'product_number');
         $result2=db('link')->where(array('product_number1'=>array('in',$result1)))->field('*')->select();
         dump($result2);
         $result3=array_column($result2, 'product_number');
         dump($result3);

    	 /*dump($result1);
          $result2=db('product')->where(array('product_number'=>array('in',$result1)))->select();
          dump($result2);
         $result3=array_column($result2, 'product_name');
         dump($result3);*/
     }

     public function test2()
     {
        
        //$title当前标题，$arrayTitle为需要查找的数组
        function getSimilar($title,$arr_title)
        {
            $arr_len= count($arr_title);
            for($i=0; $i<=($arr_len-1); $i++)
            {
            //取得两个字符串相似的字节数
            $arr_similar[$i] = similar_text($arr_title[$i],$title);
             dump($arr_similar[$i]);
            }
           dump($arr_similar);
            arsort($arr_similar); //按照相似的字节数由高到低排序
            reset($arr_similar); //将指针移到数组的第一单元
            dump($arr_similar);
            $index= 0;
            foreach($arr_similar as $old_index=>$similar)
            {
                dump($old_index);
            dump($arr_title[$old_index]);
            $new_title_array[$index] = $arr_title[$old_index];
            dump($new_title_array[$index]);
            dump($arr_title[$old_index]);
            $index++;
            }
            return $new_title_array;
         }

        $demo_title= "简明现代魔法";
        $demo_arr_title= array("简单易懂的现代魔法","简单明了的现代魔法","简明扼要的古代魔法","不简单的现代魔法","很难懂的现代魔法");
        $new_array= getSimilar($demo_title,$demo_arr_title);
        //print_r($new_array);
        echo"与[$demo_title]最相关的前三个文章是：<br/>";
        for($j=0; $j<=2; $j++)
        {
        echo($j+1).":".$new_array[$j]."<br/>";
        }


     }
     public function test3()
     {
                 function getSimilar($title,$arr_title)
                {
                    $arr_len= count($arr_title);
                    for($i=0; $i<=($arr_len-1); $i++)
                    {
                    //取得两个字符串相似的字节数
                    $arr_similar[$i] = similar_text($arr_title[$i],$title);
                     
                    }
                   
                    arsort($arr_similar); //按照相似的字节数由高到低排序
                    reset($arr_similar); //将指针移到数组的第一单元
                    dump($arr_similar);
                    $index= 0;
                    foreach($arr_similar as $old_index=>$similar)
                    {

                   
                    $new_title_array[$index] = $arr_title[$old_index];
                    
                    $index++;
                    }
                    return $new_title_array;
                 }
                  $demo_title= "家庭";
                  $demo_arr_title= array("【海洋王国】家庭套房","【海洋王国】单人房","【海洋王国】家庭餐","【海洋王国】儿童票","【海洋王国】家庭");
                    $new_array= getSimilar($demo_title,$demo_arr_title);
                    //print_r($new_array);
                    echo"与[$demo_title]最相关的前三个文章是：<br/>";
                    for($j=0; $j<=2; $j++)
                    {
                    echo($j+1).":".$new_array[$j]."<br/>";
                    }

         }
     
}